package com.tensquare.qa.controller;

import com.tensquare.qa.client.LabelClient;
import com.tensquare.qa.pojo.Problem;
import com.tensquare.qa.service.QaService;
import entity.PageResult;
import entity.Result;
import entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by WF on 2020/3/30 15:42
 */
@RestController
@RequestMapping("problem")
public class QaController {
    @Autowired
    private QaService qaService;
    @Autowired
    private LabelClient labelClient;
    //1.查询最新问题列表
    @GetMapping("newlist/{labelid}/{page}/{size}")
    public Result newlist(@PathVariable String labelid,@PathVariable int page,@PathVariable int size){
        //1.1)查询最新问题列表
        PageResult pageResult = qaService.newList(labelid,page,size);
        //1.2)返回查询结果
        return new Result(true,StatusCode.OK,"查询成功！",pageResult);
    }
    //2.查询热门问题
    @GetMapping("hotlist/{labelid}/{page}/{size}")
    public Result hotlist(@PathVariable String labelid,@PathVariable int page,@PathVariable int size){
        //2.1)查询热门问题
        PageResult pageResult = qaService.hotlist(labelid,page,size);
        //2.2)返回查询结果
        return new Result(true,StatusCode.OK,"查询热门问题成功！",pageResult);
    }
    //3.查询tensquare_base模块下的指定id的标签对象
    @GetMapping("label/{id}")
    public Result findById(@PathVariable String id){
        return labelClient.findById(id);
    }

}
